package com.ggh.jinjilive.ui.mine.adapter;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemMineDealDetailBinding;
import com.ggh.jinjilive.databinding.ItemTaskRecriveBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.live.SellGoodsMobile;
import com.ggh.jinjilive.mobile.mine.TradingDetailMobile;
import com.ggh.jinjilive.remotedata.BaseApiModule;

import java.util.List;

public class TaskReceiveAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<SellGoodsMobile> sellGoodsMobileList;

    public void setAdd(List<SellGoodsMobile> sellGoodsMobileList) {
        this.sellGoodsMobileList = sellGoodsMobileList;
        notifyDataSetChanged();
    }

    public void Add(List<SellGoodsMobile> sellGoodsMobileList) {
        this.sellGoodsMobileList.addAll(sellGoodsMobileList);
        notifyDataSetChanged();
    }



    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemTaskRecriveBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_task_recrive, parent, false);
        return new ItemViewHolder(binding);
    }

    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder,final int position) {
        SellGoodsMobile sellGoodsMobile = sellGoodsMobileList.get(position);
        ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
        if(null != sellGoodsMobile){
            //名称
            holder.binding.missionTitle.setText(sellGoodsMobile.getTitle());
            //商品图片
            Glide.with(holder.binding.storeImg).load(sellGoodsMobile.getImg()).into(holder.binding.storeImg);
            //商品标题
            holder.binding.tvName.setText(sellGoodsMobile.getName());
            //商品价格
            holder.binding.tvPrice.setText("￥"+sellGoodsMobile.getPrice());
            //任务数量
            holder.binding.missionTarget.setText(sellGoodsMobile.getNumber() +"");
            //任务保底
            holder.binding.leastReward.setText(sellGoodsMobile.getShare_profit() +"元" );
            holder.binding.leastRewardUnit.setText(sellGoodsMobile.getSecurity_time() + "小时");
            //主播要求
            holder.binding.missionLimit.setText("不确定");
            //主播分润
            switch (sellGoodsMobile.getShare_profit_type()){
                case 0:
                    holder.binding.benefit.setText(sellGoodsMobile.getShare_profit() + "%");
                    break;
                case 1:
                    holder.binding.benefit.setText(sellGoodsMobile.getShare_profit() + "¥");
                    break;
            }
            //商品收益
            holder.binding.productBenefit.setText("不确认");
            //任务状态
            holder.binding.missionStatus.setText("不确认");
        }
    }

    @Override
    public int getItemCount() {
        return null == sellGoodsMobileList ? 0 : sellGoodsMobileList.size();
    }


    class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemTaskRecriveBinding binding;
        public ItemViewHolder(@NonNull ItemTaskRecriveBinding binding) {
            super(binding.getRoot());
            this.binding = binding;

        }
    }

}